package com.abc.fast.server.oss.service.impl;

import com.abc.fast.common.utils.AssertUtil;
import com.abc.fast.server.oss.domain.enums.UploadTypeEnum;
import com.abc.fast.server.oss.domain.vo.req.UploadUrlReq;
import com.abc.fast.server.oss.service.OssService;
import com.abc.fast.server.oss.service.adapter.OssAdapter;
import com.abc.fast.oss.client.MinioTemplate;
import com.abc.fast.oss.domain.vo.req.OssReq;
import com.abc.fast.oss.domain.vo.resp.OssResp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class OssServiceImpl implements OssService {

    @Autowired
    private MinioTemplate minioTemplate;

    @Override
    public OssResp uploadUrl(Long uid, UploadUrlReq req) {
        UploadTypeEnum uploadTypeEnum = UploadTypeEnum.of(req.getType());
        AssertUtil.isNotEmpty(uploadTypeEnum, "上传类型错误");
        OssReq ossReq = OssAdapter.buildReq(req.getFileName(), uploadTypeEnum.getPath(), uid);
        // 生成预签名的对象URL
        return minioTemplate.getPreSignedObjectUrl(ossReq);
    }
}
